package controller;

import command.FormCommand;
import entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("/form")
public class FormController {

    @RequestMapping("/show")
    public String show(FormCommand formCommand){
        System.out.println("FormController.show");

        formCommand.setT("abc");
        formCommand.setP("123");
        formCommand.setH("aaa");
        formCommand.setTa("sadfsdafsdafsdafsdaf");
        formCommand.setC(Arrays.asList("1","3"));
        formCommand.setCs(new String[]{"1","3"});
        formCommand.setR("2");
        formCommand.setS("2");
        return "form";
    }

    @RequestMapping("/submit")
    public String submit(FormCommand formCommand){
        System.out.println("FormController.submit");

        System.out.println(formCommand.getT());
        System.out.println(formCommand.getP());
        System.out.println(formCommand.getH());
        System.out.println(formCommand.getTa());
        System.out.println(formCommand.getC());
        System.out.println(Arrays.toString(formCommand.getCs()));
        System.out.println(formCommand.getR());
        System.out.println(formCommand.getS());
        return "redirect:/form/show";
    }




    @ModelAttribute("map")
    public Map loadMap(){
        Map map=new HashMap();
        map.put("1","aaa");
        map.put("2","bbb");
        map.put("3","ccc");
        return map;
    }

    @ModelAttribute("users")
    public List<User> loadUsers(){
        List<User> users=new ArrayList<User>();
        users.add(new User(1,"aaa",23));
        users.add(new User(2,"bbb",45));
        users.add(new User(3,"ccc",17));
        return users;
    }












}
